<?php
/**
 * Powered By ThinkPHP 5.0.12
 * Copyright (c) 2017 http://www.bojuwang.net All rights reserved.
 * Created by PhpStorm.
 * Date: 2018/4/21 0021
 * Time: 上午 11:58
 * Author: NanTao <260053530@qq.com>
 */
namespace app\index\controller;
use think\Db;
use think\Request;
class Index extends Common
{
    public function index()
    {
        //轮播图
        $lunbo = Db::name('sys_ad')
            ->where(['category_id'=>1,'status'=>0])
            // ->limit(3)
            ->select();
        $this->assign('lunbo',$lunbo);
        $nav = Db::name('sys_ad')->where(['category_id'=>2,'status'=>0])->limit(8)->select();
        $this->assign('nav',$nav);
        $couponImg = Db::name('sys_ad')->where(['category_id'=>14,'status'=>0])->select();
        $this->assign('couponImg',$couponImg);
        // $footerImg = Db::name('sys_ad')->where(['category_id'=>12,'status'=>0])->find();
        // $this->assign('footerImg',$footerImg);

        $goodsTop = $this->getGoodsData(true);
        $this->assign('goodsTop',$goodsTop);
        $goodsRec = $this->getGoodsData(false,true,false,'');
        $this->assign('goodsRec',$goodsRec);
        return $this->fetch();
    }
    public function search()
    {
        $where = ['status'=>0];
        $per_page = 10;
        $page = input('param.page');
        $page ?:$page=0;
        $keywords = input('param.keywords');
        $keywords ? $where['title'] = ['like',"%{$keywords}%"] : '';
        $list = Db::name('goods')->where($where)->order('id desc')->limit($per_page*$page,$per_page)->select();
        if ($page) {
            if($list){
                json_msg_data(0,'ok',$list);
            }else{
                json_msg(1, '没有更过数据');
            }

        }
        $this->assign('list',$list);
        return $this->fetch();
    }

    public function test()
    {
        $list = Db::name('user')->select();
        foreach ($list as $k => $v) {
            if (empty($v['user_nickname']))
            {
                Db::name('user')->where('id',$v['id'])->update(['user_nickname'=>$v['user_name']]);
            }
        }
    }

    //活动专区
    public function activity()
    {
        $category_id = input('param.category_id');
        $data = get_article_data($category_id);
        $this->assign('data',$data);
        return $this->fetch();
    }
}